package com.weishuang.monitor.leader.task;

import com.weishuang.monitor.leader.service.*;
import com.weishuang.monitor.leader.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Slf4j
@Configuration
@EnableScheduling
public class ServerTask {

    @Autowired
    private IServersRunInfoService serversRunInfoService;

    @Autowired
    private IServerCpuRealTimeService serverCpuRealTimeService;

    @Autowired
    private IServerRamRealTimeService serverRamRealTimeService;

    @Autowired
    private IServerDiskInfoService serverDiskInfoService;

    @Autowired
    private IServerWarnInfoService serverWarnInfoService;

    /**
     * 执行服务器在线检查
     */
    @Scheduled(fixedRate = 5000)
    private void serverOnlineCheck() {
        log.debug("执行服务器在线检查！");
        serversRunInfoService.serverOnlineCheck();
    }

    /**
     * 执行限制CPU数据资源
     */
    @Scheduled(cron = "0 30 0/1 * * ?")
//    @Scheduled(cron = "0/10 * * * * ?")
    private void serverCpuDataLimit() {
        log.debug("执行Cpu数据资源限制！");
        serverCpuRealTimeService.serverCpuDataLimit();
    }

    /**
     * 执行限制Ram数据资源
     */
    @Scheduled(cron = "0 30 0/1 * * ?")
//    @Scheduled(cron = "0/10 * * * * ?")
    private void serverRamDataLimit() {
        log.debug("执行Ram数据资源限制！");
        serverRamRealTimeService.serverRamDataLimit();
    }

    /**
     * 执行Cpu使用率预警检查
     */
    @Scheduled(cron = "0 */1 * * * ?")
    private void serverCpuWarnCheck() {
        log.debug("执行Cpu使用率预警检查！");
        serverWarnInfoService.serverCpuWarnCheck();
    }

    /**
     * 执行Ram使用率预警检查
     */
    @Scheduled(cron = "0 */1 * * * ?")
    private void serverRamWarnCheck() {
        log.debug("执行Ram使用率预警检查！");
        serverWarnInfoService.serverRamWarnCheck();
    }

    /**
     * 执行Disk使用率预警检查
     */
    @Scheduled(cron = "0 */1 * * * ?")
    private void serverDiskWarnCheck() {
        log.debug("执行Disk使用率预警检查！");
        serverWarnInfoService.serverDiskWarnCheck();
    }
}
